home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / 80X86 / DOS32V33.ZIP / EXAMPLES / EG5.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-10-06  |  4.1 KB  |  134 lines

  1. ;**************************************************************************
  2. ;  EG5.ASM
  3. ;
  4. ; This program hooks the timer interrupt, IRQ 0, and then
  5. ; executes command line interpreter ( e.g command.com, 4dos.com, ect )
  6. ;
  7. ;
  8. ; DOS32 Assembly language example program
  9. ;**************************************************************************
  10. .386
  11. .model  flat
  12. .stack 200h
  13. .code
  14.  
  15.  
  16.  
  17. align 4
  18.  
  19. timer_IRQ_vector        DF ?
  20. comspec_ptr             dd ?
  21. dummy_cmd_tail          db 1,' '
  22. meag_v86                db ' Exiting program ',10,13,36
  23. mesg_pmode              db ' Hooking timer interrupt hand incrementing physical address B8000h.',10,13
  24.                         db  10,'Press any key to load and execute DOS-shell',10,13,36
  25.  
  26.  
  27.  
  28. Start32:                ; 32 bit code entry point.
  29.  
  30.  
  31.  
  32.       ; *****************  print a message *****************
  33.  
  34.         mov edx,offset mesg_pmode
  35.         mov ah,9
  36.         int 21h                     ; print string
  37.  
  38.  
  39.  
  40.     ;********** Hook Timer inerrupt ( IRQ 0 ) just for fun ****************
  41.  
  42.         mov     bl,8                        ;Save IRQ 0 interrupt vector
  43.         mov     ax,204h
  44.         int     31h
  45.         mov     dword ptr timer_IRQ_vector , edx
  46.         mov     word ptr timer_IRQ_vector[4] , cx
  47.  
  48.         mov     bl,8                      ; Set the new IRQ 0 vector
  49.         mov     edx,offset  timer_int     ; See below
  50.         mov     cx,cs                     ; CS:EDX = selector:offset
  51.         mov     ax,205h
  52.         int     31h
  53.  
  54.  
  55.         mov     ah,0                    ; wait for key
  56.         int     16h
  57.  
  58.  
  59. ;************** LOAD AND EXECUTE A PROGRAM ( command.com ) *****************
  60.  
  61. ;
  62. ; search for the "COMSPEC=" environemnt varibles
  63. ;
  64.  
  65.         mov     ax,0EE02h            ; Get DOS32 address information
  66.         int     31h                  ; Returns EDI -> environment address
  67. get_str_loop:
  68.         cmp     dword ptr [edi],'SMOC'          ; cmp the string "COMSPEC="
  69.         jne not_string
  70.         cmp     dword ptr [edi+4],'=CEP'
  71.         je got_string                           ; if equal exit loop
  72. not_string:
  73.         mov     al,0                            ; Scan environment for a zero
  74.         mov     ecx,20000                       ; and get next varible
  75.         repne   scasb
  76.         jmp  get_str_loop                       ; loop around again
  77.  
  78. got_string:
  79.         add     edi,8
  80.         mov     comspec_ptr,edi                 ; save address of the envir
  81.  
  82.  
  83. ;
  84. ; Call the 32bit version of the "load and execute" DOS service
  85. ;
  86.         mov     ah,4Bh
  87.         mov     al,0
  88.         mov     edi,00000                       ; DS:EDI -> envrironment
  89.         mov     esi,Offset dummy_cmd_tail       ; DS:ESI -> command tail
  90.         mov     edx,comspec_ptr                 ; DS:EDX -> ASCIIZ string
  91.         Int     21h
  92.  
  93. ;******* restore origonal vector of the timrer interrupt ********************
  94.  
  95.         mov     edx,dword ptr timer_IRQ_vector
  96.         mov     cx,word ptr timer_IRQ_vector[4]
  97.         mov     bl,8
  98.         mov     ax,205h
  99.         int     31h
  100.  
  101.  
  102. ; *****************  print another message *****************
  103.         mov edx,offset meag_v86
  104.         mov ah,9
  105.         int 21h
  106.  
  107. exit:
  108.         mov   ax,4c00h            ; Terminate program
  109.         int   21h
  110.  
  111.  
  112. ;
  113. ; *****************  IRQ 0  interrupt  handler *****************
  114. ;
  115. timer_int:
  116.         push  ds                        ; must save all registers used
  117.         pushad
  118.         mov   ax,_TEXT
  119.         mov   ds,ax                     ; Load DS with data selector
  120.  
  121.         mov   ax,0EE02h                 ; Get DOS32 Address information
  122.         int   31h
  123.         neg   ebx                       ; EBX = program address
  124.         add   ebx,0b8000h               ; Convert EBX to video memory
  125.         inc word ptr [ebx]              ; increment character on the screen
  126.                                         ; just to show it's doing something
  127.         popad
  128.         pop   ds
  129.         jmp   cs:timer_IRQ_vector       ; continue on interrupt chain.
  130.                                         ; must use CS because DS is unknown
  131.  
  132.  
  133. END Start32
  134.